package com.easylinkin.sm.controller;

import com.easylinkin.sm.constant.LogConstant;
import com.easylinkin.sm.entity.Log;
import com.easylinkin.sm.service.LogService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import java.util.Map;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.boot.data.CrudControllerSupport;
import site.morn.boot.rest.RestPage;
import site.morn.log.OperateGroup;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;
import site.morn.validate.group.Search;

/**
 * 日志控制器
 *
 * @author yezhihao
 * @since develop,2019/8/19
 */
@Api(tags = "日志管理")
@OperateGroup(value = "log", args = LogConstant.Module.LOG)
@RestController("LogController")
@RequestMapping("/log")
public class LogController extends CrudControllerSupport<Log, Long, LogService> {

  /**
   * 得到所有日志模块
   *
   * @return 日志模块
   *
   */
  @ApiOperation("得到所有日志模块")
  @PostMapping("/getLogModules")
  public RestMessage getLogModules() {
    List<Map<String,Object>> model = service().getLogModules();
    return RestBuilders.successMessage(model);
  }

  /**
   * 分页搜索所有日志
   *
   * @return 所有日志
   *
   */
  @ApiOperation("分页搜索日志")
  @PostMapping("/getAllLog")
  public RestMessage getAllLog(@Validated({Search.class}) @RequestBody RestPage<Log> restPage) {
    return RestBuilders.successMessage(service().getAllLog(restPage));
  }

  /**
   * 日志详情
   *
   * @return 日志详情
   *
   */
  @ApiOperation("意见反馈详情")
  @GetMapping("/getDetails")
  public RestMessage getDetails(Long id) {
    return RestBuilders.successMessage(service().getDetails(id));
  }
}
